x86/hvm: Optimise segment accesses in hvmemul_write_segment()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 2 Jul 2016 15:29:49 +0000 (16:29 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 8 Sep 2016 15:39:46 +0000 (16:39 +0100)
There is no need to read the segment information from VMCS/VMCB and cache it,
just to clobber the cached content immediately afterwards.

Write straight into the cache and set the accessed/dirty bits.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/emulate.c

index 0eb7a4d0a86a1972af5aac9f492055a66b67b769..e3bfda5bec4227fbd9dca700e0bdd4a0c02881ce 100644 (file)
@@ -1447,12 +1447,12 @@ static int hvmemul_write_segment(
 {
     struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
-    struct segment_register *sreg = hvmemul_get_seg_reg(seg, hvmemul_ctxt);
 
-    if ( IS_ERR(sreg) )
-         return -PTR_ERR(sreg);
+    if ( seg < 0 || seg >= ARRAY_SIZE(hvmemul_ctxt->seg_reg) )
+        return X86EMUL_UNHANDLEABLE;
 
-    memcpy(sreg, reg, sizeof(struct segment_register));
+    hvmemul_ctxt->seg_reg[seg] = *reg;
+    __set_bit(seg, &hvmemul_ctxt->seg_reg_accessed);
     __set_bit(seg, &hvmemul_ctxt->seg_reg_dirty);
 
     return X86EMUL_OKAY;